package com.zxx.googlemap;

import android.util.SparseArray;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.zxx.googlemap.fragment.HomeFragment;

/**
 * 实现一个Activity中嵌套Fragment的实例。
 * https://github.com/zhpanvip/BannerViewPager
 *
 * @author zqq on 2020/2/27.
 */
public class AdapterFragmentPager extends FragmentStateAdapter {

    private static final int PAGE_HOME = 0;
    private static final int PAGE_FIND = 1;
    private static final int PAGE_INDICATOR = 2;
    private static final int PAGE_OTHER = 3;

    private SparseArray<Fragment> fragment = new SparseArray<>();

    public AdapterFragmentPager(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
        init();
    }

    private void init() {
        fragment.put(PAGE_HOME, new HomeFragment());
        fragment.put(PAGE_FIND, HomeFragment.getInstance(1));
        fragment.put(PAGE_INDICATOR, new HomeFragment());
        fragment.put(PAGE_OTHER, HomeFragment.getInstance(3));
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return fragment.get(position);
    }

    @Override
    public int getItemCount() {
        return fragment.size();
    }


    //在Activity中为ViewPager2设置FragmentStateAdapter
}
